/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

//---------------------------------------------------------------------------
#ifndef MListH
#define MListH
//---------------------------------------------------------------------------
union MListElemData
{
	void* Data;
	DWORD dData;
	WORD  wData;
	BYTE  bData;
};

/*! \brief A generic, untyped, list element.
*/
class MListElement
{
public:
	MListElement(void);
	~MListElement(void);

	MListElemData Data;

	MListElement* Next;
};
//---------------------------------------------------------------------------
/*! \brief A generic list of untyped (void*) elements.

	I have writted this class before I have started to use the ones include in the \b std namespace.
	Basically it's a single linked list of one of the following element types:
		- untyped pointers (void*)
		- DWORD's
		- WORD's
		- BYTE's
		.
*/
class MList
{
private:
	MListElement* Head;
	
public:
	MList(void);
	~MList(void);

private:
	void CleanUp(void);
	MListElement* GetALE(int);

	MListElement* CreateElement(void);

public:
	//! Adds an item in front of the list
	bool AddFirst(void*);
	bool AddFirstBYTE(BYTE);
	bool AddFirstWORD(WORD);
	bool AddFirstDWORD(DWORD);
	// Adds an item at the end of the list
	bool AddLast(void*);
	bool AddLastBYTE(BYTE);
	bool AddLastWORD(WORD);
	bool AddLastDWORD(DWORD);

	//! Deletes an item from the list
	bool Delete(int);

	//! Gets the number of elements in the list
	int GetCount(void);
	//! Gets an item from the list
	void* GetItem(int);
	BYTE  GetItemBYTE(int);
	WORD  GetItemWORD(int);
	DWORD GetItemDWORD(int);
	//! Sets an item to another value
	bool SetItem(int, void*);

	//! USE WITH CARE
	MListElement* GetHead(void);

	//! Clears the list
	void Clear(void);
};
//---------------------------------------------------------------------------
#endif

